﻿
namespace ATA.Windows.Forms
{
	/// <summary>
	/// abstract NhomKhachHang typed datagridview
	/// </summary>
	[System.ComponentModel.DesignerCategoryAttribute("code")]
	public abstract class NhomKhachHangDataGridViewBase : System.Windows.Forms.UserControl
	{	
		/// <summary> 
		/// Thrown when the current Entity changed.
		/// </summary>
		public event System.EventHandler<NhomKhachHangDataGridViewEventArgs> CurrentEntityChanged;
		
		#region Fields
				
		/// <summary> 
		/// the current entity.
		/// </summary>
		private Entities.NhomKhachHang _currentNhomKhachHang = null;
		//private Dictionary<string, string> _columnsHeaders = new Dictionary<string, string>();
		
		/// <summary> 
		/// the datagridview instance
		/// </summary>
		protected System.Windows.Forms.DataGridView uxNhomKhachHangDataGridView;
		
		/// <summary> 
		/// the errorprovider
		/// </summary>
		protected System.Windows.Forms.ErrorProvider uxNhomKhachHangErrorProvider;
		
		/// <summary> 
		/// the bindingsource
		/// </summary>
		protected System.Windows.Forms.BindingSource uxNhomKhachHangBindingSource;
		
		
		/// <summary> 
		/// the DGV column associated with the NhomKhachHangId property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxNhomKhachHangIdDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the KhachHangId property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxKhachHangIdDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the LastUpdate property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxLastUpdateDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the UpdateBy property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxUpdateByDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the Level property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxLevelDataGridViewColumn;
		
		#endregion
					
		#region Combo list
		
		#endregion
		
		#region Main Datasource
		
		private Entities.TList<Entities.NhomKhachHang> _NhomKhachHangList;
				
		/// <summary> 
		/// The list of NhomKhachHang to be displayed in the DGV.
		/// </summary>
		[System.ComponentModel.Category("Data")]
		public Entities.TList<Entities.NhomKhachHang> NhomKhachHangList
		{
			get {return this._NhomKhachHangList;}
			set
			{
				this._NhomKhachHangList = value;
				this.uxNhomKhachHangBindingSource.DataSource = null;
				this.uxNhomKhachHangBindingSource.DataSource = value;
				this.uxNhomKhachHangDataGridView.DataSource = null;
				this.uxNhomKhachHangDataGridView.DataSource = this.uxNhomKhachHangBindingSource;				
				//this.uxNhomKhachHangBindingSource.ListChanged += new System.ComponentModel.ListChangedEventHandler(uxNhomKhachHangBindingSource_ListChanged);
				this.uxNhomKhachHangBindingSource.CurrentItemChanged += new System.EventHandler(OnNhomKhachHangBindingSourceCurrentItemChanged);
			}
		}
		
		private void OnNhomKhachHangBindingSourceCurrentItemChanged(object sender, System.EventArgs e)
		{
			_currentNhomKhachHang = uxNhomKhachHangBindingSource.Current as Entities.NhomKhachHang;
			
			if (_currentNhomKhachHang != null)
			{
				_currentNhomKhachHang.Validate();
			}
			//_NhomKhachHang.Validate();
			OnCurrentEntityChanged();
		}

		//void uxNhomKhachHangBindingSource_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
		//{
			//throw new Exception("The method or operation is not implemented.");
		//}		
		
		#endregion
		
		/// <summary>
		/// Gets the currently selected <c cref="Entities.NhomKhachHang"/> instance.
		/// </summary>
		public Entities.NhomKhachHang SelectedNhomKhachHang
		{
			get {return this._currentNhomKhachHang;}
		}
		
		#region other properties
		
		/// <summary>
		/// Gets or sets a value indicating whether you have provided your own data-management operations for the DataGridView control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool VirtualMode
		{
			get {return this.uxNhomKhachHangDataGridView.VirtualMode;}
			set
			{
				this.uxNhomKhachHangDataGridView.VirtualMode = value;
			}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the option to add rows is displayed to the user.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToAddRows
		{
			get {return this.uxNhomKhachHangDataGridView.AllowUserToAddRows;}
			set {this.uxNhomKhachHangDataGridView.AllowUserToAddRows = value;}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the user is allowed to delete rows from the DataGridView.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToDeleteRows
		{
			get {return this.uxNhomKhachHangDataGridView.AllowUserToDeleteRows;}
			set {this.uxNhomKhachHangDataGridView.AllowUserToDeleteRows = value;}
		}
		
		/// <summary>
		/// Gets the <c cref="DataGridView"/> instance.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public System.Windows.Forms.DataGridView DataGridView
		{
			get {return this.uxNhomKhachHangDataGridView;}
		}
		
		/// <summary>
		/// Gets a collection that contains all the columns in the control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]		
		[System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Visible)]
		//[System.ComponentModel.EditorAttribute("System.Windows.Forms.Design.DataGridViewColumnCollectionEditor, System.Design", typeof(System.Drawing.Design.UITypeEditor))] 
		public System.Windows.Forms.DataGridViewColumnCollection Columns
		{
			get { return this.uxNhomKhachHangDataGridView.Columns; }
		}
		
		#endregion
		
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.IContainer components = null;
	
		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}
	
		#region Constructor
	
		/// <summary>
		/// Initializes a new instance of the <see cref="NhomKhachHangDataGridViewBase"/> class.
		/// </summary>
		public NhomKhachHangDataGridViewBase()
		{			
			this.components = new System.ComponentModel.Container();			
			
			this.uxNhomKhachHangDataGridView = new System.Windows.Forms.DataGridView();
			this.uxNhomKhachHangBindingSource = new System.Windows.Forms.BindingSource(this.components);
			this.uxNhomKhachHangErrorProvider = new System.Windows.Forms.ErrorProvider(this.components);
			this.uxNhomKhachHangIdDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxKhachHangIdDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxLastUpdateDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxUpdateByDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxLevelDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			((System.ComponentModel.ISupportInitialize)(this.uxNhomKhachHangDataGridView)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxNhomKhachHangBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxNhomKhachHangErrorProvider)).BeginInit();
			this.SuspendLayout();
						
			// 
			// uxNhomKhachHangErrorProvider
			// 
			this.uxNhomKhachHangErrorProvider.ContainerControl = this;
			this.uxNhomKhachHangErrorProvider.DataSource = this.uxNhomKhachHangBindingSource;						
			// 
			// uxNhomKhachHangDataGridView
			// 
			this.uxNhomKhachHangDataGridView.AutoGenerateColumns = false;
			this.uxNhomKhachHangDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
			this.uxNhomKhachHangDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
		this.uxNhomKhachHangIdDataGridViewColumn,
		this.uxKhachHangIdDataGridViewColumn,
		this.uxLastUpdateDataGridViewColumn,
		this.uxUpdateByDataGridViewColumn,
		this.uxLevelDataGridViewColumn			});
			this.uxNhomKhachHangDataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
			this.uxNhomKhachHangDataGridView.Location = new System.Drawing.Point(0, 0);
			this.uxNhomKhachHangDataGridView.Name = "uxNhomKhachHangDataGridView";
			this.uxNhomKhachHangDataGridView.Size = new System.Drawing.Size(470, 300);
			this.uxNhomKhachHangDataGridView.TabIndex = 0;	
			this.uxNhomKhachHangDataGridView.BackgroundColor = System.Drawing.Color.WhiteSmoke;
			this.uxNhomKhachHangDataGridView.EnableHeadersVisualStyles = false;
			this.uxNhomKhachHangDataGridView.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.OnNhomKhachHangDataGridViewDataError);
			this.uxNhomKhachHangDataGridView.CellValueNeeded += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnNhomKhachHangDataGridViewCellValueNeeded);
			this.uxNhomKhachHangDataGridView.CellValuePushed += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnNhomKhachHangDataGridViewCellValuePushed);
			
			//
			// uxNhomKhachHangIdDataGridViewColumn
			//
			this.uxNhomKhachHangIdDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxNhomKhachHangIdDataGridViewColumn.DataPropertyName = "NhomKhachHangId";
			this.uxNhomKhachHangIdDataGridViewColumn.HeaderText = "NhomKhachHangId";
			this.uxNhomKhachHangIdDataGridViewColumn.Name = "uxNhomKhachHangIdDataGridViewColumn";
			this.uxNhomKhachHangIdDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxNhomKhachHangIdDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxNhomKhachHangIdDataGridViewColumn.ReadOnly = false;		
			//
			// uxKhachHangIdDataGridViewColumn
			//
			this.uxKhachHangIdDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxKhachHangIdDataGridViewColumn.DataPropertyName = "KhachHangId";
			this.uxKhachHangIdDataGridViewColumn.HeaderText = "KhachHangId";
			this.uxKhachHangIdDataGridViewColumn.Name = "uxKhachHangIdDataGridViewColumn";
			this.uxKhachHangIdDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxKhachHangIdDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxKhachHangIdDataGridViewColumn.ReadOnly = false;		
			//
			// uxLastUpdateDataGridViewColumn
			//
			this.uxLastUpdateDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxLastUpdateDataGridViewColumn.DataPropertyName = "LastUpdate";
			this.uxLastUpdateDataGridViewColumn.HeaderText = "LastUpdate";
			this.uxLastUpdateDataGridViewColumn.Name = "uxLastUpdateDataGridViewColumn";
			this.uxLastUpdateDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxLastUpdateDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxLastUpdateDataGridViewColumn.ReadOnly = false;		
			//
			// uxUpdateByDataGridViewColumn
			//
			this.uxUpdateByDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxUpdateByDataGridViewColumn.DataPropertyName = "UpdateBy";
			this.uxUpdateByDataGridViewColumn.HeaderText = "UpdateBy";
			this.uxUpdateByDataGridViewColumn.Name = "uxUpdateByDataGridViewColumn";
			this.uxUpdateByDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxUpdateByDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxUpdateByDataGridViewColumn.ReadOnly = false;		
			//
			// uxLevelDataGridViewColumn
			//
			this.uxLevelDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxLevelDataGridViewColumn.DataPropertyName = "Level";
			this.uxLevelDataGridViewColumn.HeaderText = "Level";
			this.uxLevelDataGridViewColumn.Name = "uxLevelDataGridViewColumn";
			this.uxLevelDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxLevelDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxLevelDataGridViewColumn.ReadOnly = false;		
			
			// this
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.Controls.Add(this.uxNhomKhachHangDataGridView);
			this.Name = "NhomKhachHangDataGridView";
			this.Size = new System.Drawing.Size(470, 300);
			((System.ComponentModel.ISupportInitialize)(this.uxNhomKhachHangErrorProvider)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxNhomKhachHangDataGridView)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxNhomKhachHangBindingSource)).EndInit();
			this.ResumeLayout(false);
		}
		#endregion
				
		#region events
		
		/// <summary>
		/// Raised the CurrentEntityChanged event.
		/// </summary>
		protected void OnCurrentEntityChanged()
		{
			if (CurrentEntityChanged != null)
			{
				NhomKhachHangDataGridViewEventArgs args = new NhomKhachHangDataGridViewEventArgs();
				args.NhomKhachHang = _currentNhomKhachHang;
				CurrentEntityChanged(this, args); 
			}
		}
		
		#endregion
		
		/// <summary>
		/// Strongly typed event 
		/// </summary>
		public class NhomKhachHangDataGridViewEventArgs : System.EventArgs
		{
			private Entities.NhomKhachHang	_NhomKhachHang;
	
			/// <summary>
			/// the  Entities.NhomKhachHang instance.
			/// </summary>
			public Entities.NhomKhachHang NhomKhachHang
			{
				get { return _NhomKhachHang; }
				set { _NhomKhachHang = value; }
			}	
		}
		
		/// <summary>
		/// Handles the DataError event of the uxNhomKhachHangDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewDataErrorEventArgs"/> instance containing the event data.</param>
		protected void OnNhomKhachHangDataGridViewDataError(object sender, System.Windows.Forms.DataGridViewDataErrorEventArgs e)
		{
			System.Diagnostics.Debug.WriteLine(string.Format( "{0}, {1}", e.ColumnIndex, e.RowIndex));
		}
		
		/// <summary>
		/// Handles the CellValueNeeded event of the uxNhomKhachHangDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnNhomKhachHangDataGridViewCellValueNeeded(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxNhomKhachHangDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxNhomKhachHangIdDataGridViewColumn":
						e.Value = NhomKhachHangList[e.RowIndex].NhomKhachHangId;
						break;
					case "uxKhachHangIdDataGridViewColumn":
						e.Value = NhomKhachHangList[e.RowIndex].KhachHangId;
						break;
					case "uxLastUpdateDataGridViewColumn":
						e.Value = NhomKhachHangList[e.RowIndex].LastUpdate;
						break;
					case "uxUpdateByDataGridViewColumn":
						e.Value = NhomKhachHangList[e.RowIndex].UpdateBy;
						break;
					case "uxLevelDataGridViewColumn":
						e.Value = NhomKhachHangList[e.RowIndex].Level;
						break;
				default:
				break;
			}
		}
		
		/// <summary>
		/// Handles the CellValuePushed event of the uxNhomKhachHangDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnNhomKhachHangDataGridViewCellValuePushed(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxNhomKhachHangDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxNhomKhachHangIdDataGridViewColumn":
						NhomKhachHangList[e.RowIndex].NhomKhachHangId = (System.Guid)e.Value;
						break;
					case "uxKhachHangIdDataGridViewColumn":
						NhomKhachHangList[e.RowIndex].KhachHangId = (System.String)e.Value;
						break;
					case "uxLastUpdateDataGridViewColumn":
						NhomKhachHangList[e.RowIndex].LastUpdate = (System.DateTime)e.Value;
						break;
					case "uxUpdateByDataGridViewColumn":
						NhomKhachHangList[e.RowIndex].UpdateBy = (System.Int32)e.Value;
						break;
					case "uxLevelDataGridViewColumn":
						NhomKhachHangList[e.RowIndex].Level = (System.Int16?)e.Value;
						break;
				default:
				break;
			}
		}
	}
}
